<template>
  <div class="demand-pie">
    <div class="demand-pie-header">
      <div>总需求数</div>
      <div>{{ addThousandsSeparator(total) }}</div>
    </div>

    <div class="demand-pie-content">
      <div class="content-title">
        <div class="list-title-left">
          <div class="message">模块</div>
        </div>
        <div class="list-title-right">
          <div>数量</div>
          <div>占比</div>
        </div>
      </div>
      <div class="content-list">
        <div class="content-list-item"
             v-for="(item, index) in data"
             :key="index">
          <div class="list-item-left">
            <arco-tooltip :content="item.name"
                       :content-class="{ 'hidden-tootip': item.name.length < 10 }">
              <div class="message">{{ item.name }}</div>
            </arco-tooltip>
          </div>
          <div class="list-item-right">
            <div>{{ addThousandsSeparator(item.value) }}</div>
            <div>{{ item.percent }}</div>
          </div>
        </div>
      </div>
    </div>
    <VptPie :chartData="data"
            autoRander
            v-bind="pieProps"></VptPie>
  </div>
</template>

<script setup>
import VptPie from "@/components/echarts/vpt-pie/index.vue";
import { addThousandsSeparator } from "@/utils/formatter.js";
import { getPercentValue } from "@/utils/formatter.js";
import { computed } from "vue";
import { fontSize } from "@/utils/rem/rem.js";

const props = defineProps({
  pieData: { type: Array, default: () => [] },
  isLandscape: { type: Boolean, default: false },
});

// const pieProps = computed(() => {
//     const otherProps = props.isLandscape ? getOtherPieProps() : {};

//     return {
//         center: ['50%', '35%'],
//         radius: ['38%', '50%'],
//         legendProps: {
//             top: '64%',
//             left: '18%',
//             itemGap: 10
//         },
//         titleProps: {
//             left: '48%',
//             top: '25%',
//         },
//         color: ['#2175DB', '#57C5FF', '#00B675', '#EDC600'],
//         ...otherProps
//     }
// })

const data = computed(() => {
  return props.pieData.map((item, index) => {
    return {
      ...item,
      percent: `${getPercentValue(
        props.pieData.map((v) => v.value),
        index,
        1
      )}%`,
    };
  });
});

const total = computed(() => {
  return props.pieData.reduce((pre, cur) => {
    return pre + cur.value;
  }, 0);
});

// const getOtherPieProps = () => {
//     return {
//         titleProps: {
//             left: '48%',
//             top: '25%',
//         },
//         legendProps: {
//             top: '64%',
//             left: '20%',
//             itemGap: 10,
//             itemWidth: fontSize(12),
//             itemHeight: fontSize(12)
//         },
//         legendFontSize: 12,
//         legendNamePadding: [0, fontSize(40), 0, fontSize(10)],
//         titleFontSize: 14,
//         totalFontSize: 24
//     }
// }
</script>

<style lang="less" scoped>
.demand-pie {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0.12rem 0.12rem 0.16rem 0.12rem;
  background: #1470cc1a;
  border: 0.01rem solid #e6ebf5;
  // border: 1px solid #006affcf;
  box-sizing: border-box;

  .demand-pie-header {
    margin-bottom: 0.12rem;

    div {
      &:first-child {
        color: #ffffffb3;
        font-size: 0.14rem;
        line-height: 0.2rem;
        margin-bottom: 0.08rem;
      }

      &:last-child {
        font-size: 0.18rem;
        color: #fff;
        line-height: 0.22rem;
      }
    }
  }

  .demand-pie-content {
    // flex: 1;
    // height: 0;
    height: calc(100% - 22rem);
    display: flex;
    flex-direction: column;
    // padding: 0.12rem;
    box-sizing: border-box;
    // border: 1px solid #006affcf;
    border: 0.01rem solid #e6ebf5;

    .content-title {
      // width: 2.25rem;
      height: 0.3rem;
      background: #0d2b4f;
      // position: relative;
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: #fff;
      font-size: 0.14rem;
      line-height: 0.22rem;
      z-index: 10;
      padding: 0 0.2rem;

      &:not(:last-child) {
        // margin-bottom: 0.1rem;
      }
      .list-title-left {
        flex: 1;
        width: 0;

        .message {
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          // margin-left: 0.2rem;
        }
      }

      .list-title-right {
        display: flex;
        align-items: center;

        div {
          &:last-child {
            width: 0.5rem;
            text-align: center;
          }

          &:first-child {
            // padding-right: 0.15rem;
            margin-right: 0.1rem;
            //   border-right: 1px solid #fff;
          }
        }
      }
    }

    .content-list {
      // position: relative;
      flex: 1;
      width: 95%;
      padding: 0.12rem;
      // top: 0.3rem;
      z-index: 9;
      overflow-y: auto;

      .content-list-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #fff;
        font-size: 0.14rem;
        line-height: 0.22rem;

        &:not(:last-child) {
          margin-bottom: 0.1rem;
        }
        .list-item-left {
          flex: 1;
          width: 0;

          .message {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }

        .list-item-right {
          display: flex;
          align-items: center;

          div {
            &:last-child {
              width: 0.5rem;
            }

            &:first-child {
              padding-right: 0.1rem;
              margin-right: 0.1rem;
              border-right: 1px solid #fff;
            }
          }
        }
      }
    }
  }
}
</style>

<style lang="less">
.hidden-tootip {
  display: none;
}
</style>